home *** CD-ROM | disk | FTP | other *** search
- Path: kettle.magna.com.au!news
- From: peter@magna.com.au (Peter J Brock)
- Newsgroups: comp.lang.c++
- Subject: VC++ 4.0 Template bug?
- Date: Sat, 16 Mar 1996 12:09:51 GMT
- Organization: Me
- Message-ID: <4ieatm$ibs@kettle.magna.com.au>
- Reply-To: peter@magna.com.au
- NNTP-Posting-Host: enterprise.magna.com.au
- X-Newsreader: Forte Free Agent v0.55
-
- /*
- The following code illustrates what I think is a bug in the
- implementation of templates in MS Visual C++ 4.0.
-
- This is the greatly reduced code that reproduces the problem
- that I encountered when developing a matrix class based on the
- STL vector. This code does not use any STL classes.
-
- The problems is that the member function A::test produces
- a compile time error for the line
-
- fdTest() = 5.0; //error C2064: term does not evaluate to a function
-
- This line also exist in main(), and produces no error.
- The work arround was to explicitly define the member function
-
- inline double& VeryTesting<double>::operator ()()
-
- This is commented out in the code, so just uncomment to see
- that it does indeed remedy the problem.
-
- Note: this should not be required.
-
- Questions;
- 1) Has anybody else had this problem?
- 2) What are some of the other template errors in MS Visual C++ 4.0?
- 3) Is it safe to use templates in VC++ 4.0 given the compiler gets
- confused?
-
- Note: In the process of producing this example I noticed other strange
- errors being reported. One was that the class was already defined.
-
-
- Cheers,
- Peter J Brock http://www.magna.com.au/~peter
-
-
- */
-
- //____________________________________________________________
- // test.cpp
-
- template <class T>
- class VeryTesting
- {
- public:
- VeryTesting();
-
- T& operator()();
-
- T m_T;
- };
-
- template <class T>
- inline
- VeryTesting<T>::VeryTesting ()
- {
- }
-
- template <class T>
- inline T&
- VeryTesting<T>::operator ()()
- {
- return m_T;
- }
-
- /* Uncomment this block of code and it all works! Why?
- inline double&
- VeryTesting<double>::operator ()()
- {
- return m_T;
- }
- */
-
- class A
- {
- public :
- A(){}
- ~A(){}
-
- VeryTesting<double>& test(VeryTesting<double>& fdTest)
- {
- fdTest() = 5.0; //error C2064: term does not evaluate to a function
- return fdTest;
- }
-
- };
-
- main()
- {
- VeryTesting<double> f;
- f() = 5.0;
-
- A aObject;
- aObject.test(f);
- }
-
- /*
-
- Funny things happen with this module.
-
- Try variations of this and you will see all manner of errors.
- In the attempt to minimize this sample I had errors telling me
- that the template class had previously been defined. Just where it
- could have been defined escapes me. Maybe MS has an undocumented
- VeryTesting class which just happens to be templated based.
-
-
- */
- //____________________________________________________________
-
-
-